package com.wan.adapter

import android.support.v4.view.PagerAdapter
import android.view.View
import android.view.ViewGroup
import com.wan.uitls.PagerItemClickListener


class HomeVpAdapter(private var datas: ArrayList<View>, private var listener: PagerItemClickListener) : PagerAdapter() {

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun getCount(): Int {
        return datas.size
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        println("HomeVPAdapter: destroyItem==> ")
        container.removeView(`object` as View)
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        var view = datas[position]
        view.setOnClickListener {
            listener.onPagerItemClickListener(position)
        }
        container.addView(view)
        return view
    }
}